import 'package:aitao_flutter/mine/controller/setting_page_controller.dart';
import 'package:aitao_flutter/style/box_style.dart';
import 'package:aitao_flutter/style/edgeInsets_style.dart';
import 'package:aitao_flutter/style/text_style.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../common_ui/back_nav.dart';
import '../../common_ui/confirm_btn.dart';
import '../../const/common_const.dart';
import '../../style/color_style.dart';

class SettingPage extends StatelessWidget {
  SettingPage({Key? key}) : super(key: key);
  final SettingPageController controller = Get.put(SettingPageController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ColorStyle.backGroundColor,
      appBar: BackNavigation(title: MineStringConst.settingText),
      body: ListView(
        children: [
          listItem(controller.tabListData[0]),
          listItem(controller.tabListData[1]),
          Container(
            width: double.infinity,
            height: 20.w,
            color: ColorStyle.backGroundColor,
          ),
          listItem(controller.tabListData[2]),
          listItem(controller.tabListData[3]),
          Container(
            width: double.infinity,
            height: 20.w,
            color: ColorStyle.backGroundColor,
          ),
          listItem(controller.tabListData[4]),
          GetBuilder<SettingPageController>(builder: ((controller) {
            return listItem(controller.tabListData[5]);
          })),
          listItem(controller.tabListData[6]),
          Container(
            width: double.infinity,
            height: 20.w,
            color: ColorStyle.backGroundColor,
          ),
          listItem(controller.tabListData[7]),
          Container(
            width: double.infinity,
            height: 20.w,
            color: ColorStyle.backGroundColor,
          ),
          listItem(controller.tabListData[8]),
          Container(
            width: double.infinity,
            height: 20.w,
            color: ColorStyle.backGroundColor,
          ),
          _logoutWidget()
        ],
      ),
    );
  }

  Widget _logoutWidget() {
    return Container(
      padding: EdgeInsetsStyle.edgeInsets(20, 20),
      color: ColorStyle.whiteColor,
      child: ConfirmButton(
        title: '退出登录',
        backGroundColor: ColorStyle.themeColor,
        titleColor: ColorStyle.whiteColor,
        callBack: () {
          controller.logoutClick();
        },
      ),
    );
  }

  Widget listItem(Map item) {
    return GestureDetector(
      child: Container(
        height: 48.h,
        color: ColorStyle.whiteColor,
        padding: EdgeInsetsStyle.edgeInsets(20, 0),
        child: Row(
          children: [
            Text(
              item['title'],
              style: Styles.normalText_15,
            ),
            const Spacer(),
            Text(
              item['des'],
              style: Styles.greyText_13,
            ),
            Box.hBox6,
            const Icon(
              Icons.arrow_forward_ios_rounded,
              color: ColorStyle.aaaaaaColor,
              size: 16,
            )
          ],
        ),
      ),
      onTap: () {
        controller.cellClick(item['title']);
      },
    );
  }
}
